home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
indents.zip
/
comment.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-30
|
18KB
|
412 lines
/**
* Copyright (c) 1985 Sun Microsystems, Inc.
* Copyright (c) 1980 The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted provided
* that the above copyright notice and this paragraph are duplicated in all
* such forms and that any documentation, advertising materials, and other
* materials related to such distribution and use acknowledge that the
* software was developed by the University of California, Berkeley, the
* University of Illinois, Urbana, and Sun Microsystems, Inc. The name of
* either University or Sun Microsystems may not be used to endorse or
* promote products derived from this software without specific prior written
* permission. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
* OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "globals.h"
#ifndef lint
# ifndef ANSIC
static char sccsid[] = "@(#)comment.c 6.0 (Berkeley) 92/06/15";
# endif /* ANSIC */
#endif /* not lint */
/**
* NAME: pr_comment
*
* FUNCTION: This routine takes care of scanning and printing comments.
*
* ALGORITHM: 1) Decide where the comment should be aligned, and if lines should
* be broken. 2) If lines should not be broken and filled, just copy up to
* end of comment. 3) If lines should be filled, then scan through input_buffer
* copying characters to com_buf. Remember where the last blank, tab, or
* new line was. When line is filled, print up to last blank and continue
* copying.
*
* HISTORY: November 1976, D A Willcox of CAC, Initial coding.
* 12/6/76, D A Willcox of CAC, Modification to handle UNIX-style comments.
*/
/* this routine processes comments. It makes an attempt to keep comments
* from going over the max. line length. If a line is too long, it moves
* everything from the last blank to the next comment line. Blanks and tabs
* from the beginning of the input line are removed */
#ifdef ANSIC
void pr_comment(char *combuf)
#else /* ANSIC */
pr_comment()
char *combuf;
#endif /* ANSIC */
{
int now_col; /* column we are in now */
int adj_max_col;/* Adjusted max_col for when we decide to
* spill comments over the right margin */
char *last_bl = NULL; /* points to the last blank in the output
* buffer */
char *t_ptr = NULL; /* used for moving string */
int unix_comment; /* tri-state variable used to decide if
* it is a UNIX-style comment. 0 means
* only blanks since '/''*', 1 means
* regular style comment, 2 means UNIX
* style comment */
int break_delim = comment_delimiter_on_blankline;
int l_just_saw_decl = ps.just_saw_decl;
#if 0
int ps.last_nl = 0; /* true iff the last significant thing
* we've seen is a newline */
#endif /* 0 */
int one_liner = 1; /* true iff this comment is a one-liner */
adj_max_col = max_col;
ps.just_saw_decl = 0;
last_bl = 0; /* no blanks found so far */
ps.box_com = false; /* at first, assume that we are not in a
* boxed comment or some other comment that
* should not be touched */
++ps.out_coms; /* keep track of number of comments */
unix_comment = 1; /* set flag to let us figure out if there is
* a unix-style comment ** DISABLED: use 0 to
* re-enable this hack! */
/* Figure where to align and how to treat the comment */
if (ps.col_1 && !format_col1_comments) { /* if comment starts in
* column 1 it should not be
* touched */
ps.box_com = true;
ps.com_col = 1;
} else {
if (*buf_ptr == '-' || *buf_ptr == '*') {
ps.box_com = true; /* a comment with a '-' or '*' immediately
* after the '/''*' is assumed to be a boxed
* comment */
break_delim = 0;
}
if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) {
/* klg: check only if this line is blank */
/* If this (*and previous lines are*) blank, don't put comment
* way out at left */
ps.com_col = (ps.ind_level - ps.unindent_displace) * ps.ind_size + 1;
adj_max_col = block_comment_max_col;
if (ps.com_col <= 1)
ps.com_col = 1 + !format_col1_comments;
} else {
register int target_col;
break_delim = 0;
if (s_code != e_code)
target_col = count_spaces(compute_code_target(), s_code);
else {
target_col = 1;
if (s_lab != e_lab)
target_col = count_spaces(compute_label_target(), s_lab);
}
ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? ps.decl_com_ind : ps.com_ind;
if (ps.com_col < target_col)
ps.com_col = target_col +
(tabsize - ((target_col - 1) % tabsize)); /* JHT 22oct89 */
if (else_or_endif) {/* -cp PETER */
ps.com_col = ps.else_endif_col; /* -cp PETER */
else_or_endif = false; /* -cp PETER */
/* We want the comment to appear one space after the #else or
* #endif. -cp PETER */
if (ps.com_col < target_col) /* -cp PETER */
ps.com_col = target_col + 1; /* -cp PETER */
} /* -cp PETER */
if (ps.com_col + 24 > adj_max_col)
adj_max_col = ps.com_col + 24;
}
}
if (ps.box_com) {
buf_ptr[-2] = 0;
ps.n_comment_delta = 1 - count_spaces(1, in_buffer);
buf_ptr[-2] = '/';
} else {
ps.n_comment_delta = 0;
while (*buf_ptr == ' ' || *buf_ptr == '\t')
buf_ptr++;
}
ps.comment_delta = 0;
*e_com++ = '/'; /* put '/''*' into buffer */
if (ps.cc_comment) /* (or '/''/') */
*e_com++ = '/';
else
*e_com++ = '*';
if (*buf_ptr != ' ' && !ps.box_com)
*e_com++ = ' ';
*e_com = '\0';
if (troff) {
now_col = 1;
adj_max_col = 80;
} else
now_col = count_spaces(ps.com_col, s_com); /* figure what column we
* would be in if we
* printed the comment
* now */
/* Start to copy the comment */
while (1) { /* this loop will go until the comment is
* copied */
if (*buf_ptr >= 040 && *buf_ptr != '*')
ps.last_nl = 0;
check_size(com);
switch (*buf_ptr) { /* this checks for various spcl cases */
case 014: /* check for a form feed */
if (!ps.box_com) { /* in a text comment, break the line here */
ps.use_ff = true;
/* fix so dump_line uses a form feed */
dump_line();
last_bl = 0;
*e_com++ = ' ';
*e_com++ = '*';
*e_com++ = ' ';
while (*++buf_ptr == ' ' || *buf_ptr